//
//  XLUserCenterPresenter.m
//  industry
//
//  Created by xl on 2020/11/12.
//  Copyright © 2020 Haier. All rights reserved.
//

#import "XLUserCenterPresenter.h"
#import "XLUserCenterPresenterProtocol.h"
#import "XLUserCenterAdapter.h"
#import "XLUserCenterInteractorProtocol.h"
#import "XLAppletModel.h"
#import "XLUserCenterViewProtocol.h"


@interface XLUserCenterPresenter ()<XLUserCenterPresenterProtocol>

@end
@implementation XLUserCenterPresenter

- (void)dealloc {
    XLLog(@"XLUserCenterPresenter dealloc");
}

#pragma mark - XLUserCenterPresenterProtocol
- (NSArray *)getFunctions {
    return @[XLUserCenterAdapterCommonProblem,
             XLUserCenterAdapterAccountProblem,
             XLUserCenterAdapterAboutUs];
}

- (void)handleCellData:(id)data {
    if ([data isEqualToString:XLUserCenterAdapterAccountProblem]) {
        XLSend(self.baseController.interactor, XLUserCenterInteractorProtocol, gotoAccountSafeVC);
    } else if ([data isEqualToString:XLUserCenterAdapterAboutUs]) {
        XLSend(self.baseController.interactor, XLUserCenterInteractorProtocol, gotoAboutUsVC);
    } else if ([data isEqualToString:XLUserCenterAdapterCommonProblem]) {
        XLSend(self.baseController.interactor, XLUserCenterInteractorProtocol, gotoProblemVC);
    }
}

- (void)requestFetchMyAppletList {
    XLHttpRequest *request = [[XLHttpRequest alloc] init];
    WEAKSELF
    [request requestWithMethod:XLHttpMedthTypeGET url:XLMyInfoAppletListUrl params:nil isExtraParams:NO successBlock:^(NSDictionary *dict) {
        STRONGSELF
        id data = [dict objectForKey:@"data"];
        if ([data isKindOfClass:[NSDictionary class]]) {
            NSDictionary *temDic = (NSDictionary *)data;
            XLAppletModel *archModel = [XLAppletModel mj_objectWithKeyValues:temDic[@"archives"]];
            XLAppletModel *busModel = [XLAppletModel mj_objectWithKeyValues:temDic[@"businessCard"]];
            XLSend(strongSelf.baseController.cView, XLUserCenterViewProtocol, refreshCurrentCardModel:busModel archiveModel:archModel);
            
        }
    } failBlock:^(XLServerRequestsStatus status, XLNetworkReachabilityStatus reachability, NSError *error, NSDictionary *dict) {
        
    }];
}
@end
